/**
 * 登录模块，提供登录相关业务功能
 * 
 * @Date: 2015-6-16
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","sysmanMain", "bizProto","btnServ"],
		function($,datagridServ, sysmanMain, bizProto,btnServ) {

			'use strict';

			var 
				//锚记datagrid目标元素
				
				//初始化后的datagrid dom对象
				$grid,
				//编辑弹窗对象及弹窗按钮对象
				$edit_window,$edit_window_height=500,$edit_window_width=900,window_btn,
				
				//业务表单对象
				flowHistoricUrl='/flowOperator/flowHistorics.action',
				rootId='#panel-supply-inquiry';
				
			var public_method = {				
				
				
				clickRow:function(index,data){
					if(window.console){
						console.info('clicked index: ' + index)
					}
					var $grid = $( rootId +' table.dg-list')
					$($grid).datagrid('clearSelections')
					$($grid).datagrid('selectRow',index)
					var rootPath = '/'+sysmanMain.getRootPath();
					
					var btn = $(rootId+' div.form-panel a.function-btn')
					$(btn).unbind('click')
					$(btn).bind('click',public_method.changePanel)
					
					var $form = rootId+' div.form-panel form'
					var _selectedRecord = $($grid).datagrid('getSelected')
					$($form).form('load',_selectedRecord)
					
					var $gridHistoric = $(rootId+' table.historics')
					
					
					
					var _historicParam ={
						
						queryParams:{flowInstId:_selectedRecord.flowInstId}							
					}
					
					var _historicOptions = $gridHistoric.datagrid('options')
					
					if(_historicOptions && _historicOptions.url){
						$gridHistoric.datagrid('load',_historicParam.queryParams)
					}else{
						_historicParam.url = rootPath + flowHistoricUrl,
						$gridHistoric.datagrid(_historicParam)
					}
						
					
					public_method.changePanel()
				},
				
				changePanel:function(){
					
					var $listPanel = $(rootId+' div.list-panel' )
					var $formPanel = $(rootId +' div.form-panel' )
					
					public_method.togglePanel({target:$listPanel})
					public_method.togglePanel({target:$formPanel})
				},
				
				/**
				 * 打开或关闭详情页面
				 * @param _options.target
				 */
				
				togglePanel : function(_options) {
					var _queryParam = {}
					//获取当前模块配置
					var _target
					
					if(_options && _options.target && _options.target.length>0){
						_target= _options.target
						if(_target.length>0){
							
							var _tmp,isClosed
							var _tmpPanel = $(_target).closest('div.panel')
							isClosed=$(_tmpPanel).attr('style')					
							 
							if(isClosed){
								isClosed = isClosed.toLowerCase();
								_tmp = isClosed.indexOf('display: none')
								if(_tmp<0){
									_target.panel('close')
								}else{
									_target.panel('open')
								}
							}
								
							
						}
					}
				}

			};

			var private_method ={
				/**
				 * 更新historic列表组件
				 */
				fillHistoricInfo:function(){
					
				}
			}
			return public_method;

		});